1. Field of the Invention
The present invention relates to a method for establishing a Gray code, and more specifically, to a method for establishing a Gray code count sequence capable of counting any number of elements and a counter circuit related to the method.
2. Description of the Prior Art
Binary counters are a common circuit element required in digital systems such as personal computers or programmable controllers. Generally speaking, a binary counter counts numbers in a binary manner (e.g. 0000- greater than 0001- greater than 0010- greater than 0011- greater than 0100- greater than  . . . etc.). However, when a counter value switches to a next counter value, over one bit may need to change simultaneously. For instance, from 0001 to 0010, the least significant bit changes from 0 to 1 and the second least significant bit changes from 1 to 0. When multiple bits change simultaneously, a transient value such as 0011 may cause a glitch in the output of the binary counter so that a circuit using the output of the binary counter may not work normally.
In order to solve the problem mentioned above, a Gray code counter is used for counting. The Gray code counter counts numbers in a Gray code count sequence. Please refer to FIG. 1 showing a list of decimal numbers 0-15 listed in sequence and their corresponding four-bit binary Gray code values. Using the Gray code count sequence, only one bit changes when switching from a counter value to the next counter value, and the last code word returns to the first code word by only changing one bit. This is referred to as the property of Gray codes throughout the following description. In this manner, Gray codes solve the problem mentioned above. In FIG. 1, the bit switch sequence indicates which bit changes when switching from the current counter value to the next counter value. If this sequence is regarded as an ordered set, in any ordered sub-set of the set, there will be at least one number which appears an odd number of times. This is referred to as the property of the bit switching sequence throughout the following description.
However, conventional methods can only establish Gray code count sequences for 2M elements, wherein M is the number of bits of each counter value, also referred to as a code word. A sequence for more than or less than 2M elements but not having a glitch in output of the counter circuit is impossible in the prior art. In other words, when the last element returns to the first element, there is still over one bit that needs to be changed.
It is therefore a primary objective of the present invention to provide a method for establishing a Gray code count sequence capable of counting any number of elements and a counter circuit related to the method.
Briefly summarized, a method for establishing a Gray code count sequence is disclosed. The method for establishing a Gray code count sequence having N code words includes determining a first bit switch sequence having 2Mxe2x88x921 elements and the property of the bit switching sequence according to a first Gray code count sequence having 2M code words, wherein 2M is larger than N; determining a second bit switch sequence having Nxe2x88x921 elements and the property of the bit switching sequence according to the first bit switch sequence; and determining a second Gray code count sequence according to the second bit switch sequence.
These and other objectives of the present invention will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiment that is illustrated in the various figures and drawings.